//
//  IAAInfoMsgHeaderTView.m
//  iPadAuditAuthorise
//
//  Created by XiangDongMBP on 16/9/6.
//  Copyright © 2016年 XiangDong. All rights reserved.
//

#import "IAAInfoMsgHeaderTView.h"
#import <Masonry.h>
#import "GlobalHeader.h"

@interface IAAInfoMsgHeaderTView ()

@property (nonatomic, strong) NSArray<UIImage *> *imgArray;

@end

@implementation IAAInfoMsgHeaderTView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self initSubViews];
        [self initLogicData];
    }
    return self;
}

- (void)initSubViews {
    self.imageView = [UIImageView new];
    [self.contentView addSubview:self.imageView];
    
    self.titleLabel = [UILabel new];
    self.titleLabel.font = [UIFont systemFontOfSize:18.0];
    self.titleLabel.textColor = IAA_COLOR_0x129CFF(1.0);
    [self.contentView addSubview:self.titleLabel];
    
    self.cntLabel = [UILabel new];
    self.cntLabel.backgroundColor = IAA_COLOR_0xF8E936(1.0);
    self.cntLabel.textColor = [UIColor whiteColor];
    self.cntLabel.layer.cornerRadius = 5;
    self.cntLabel.layer.masksToBounds = YES;
    self.cntLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.cntLabel];
}

- (void)initLogicData {
    self.imgArray = @[[UIImage imageNamed:@"infoMsg_market"],
                      [UIImage imageNamed:@"infoMsg_alarm"],
                      [UIImage imageNamed:@"infoMsg_money"],
                      [UIImage imageNamed:@"infoMsg_device"],
                      [UIImage imageNamed:@"infoMsg_business"]];
}

+ (BOOL)requiresConstraintBasedLayout {
    return YES;
}

- (void)updateConstraints {
    [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView).with.offset(15);
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(32, 32));
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.imageView.mas_trailing).with.offset(15);
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.cntLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.titleLabel.mas_trailing).with.offset(15);
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(@35);
    }];
    
    [super updateConstraints];
}

//- (void)awakeFromNib {
//    self.titleArray = @[@"营销识别信息", @"风险预警信息", @"大额转账提示"];
//    self.cntLabel.layer.cornerRadius = 5;
//    self.contentView.backgroundColor = [UIColor whiteColor];
//}

- (void)configViewWithCnt:(NSInteger)cnt title:(NSString *)title section:(NSInteger)section {
    NSInteger index = section % self.imgArray.count;    //防止过多数据，没有图片显示
    self.imageView.image = self.imgArray[index];
    self.titleLabel.text = title;
    self.cntLabel.text = [NSString stringWithFormat:@"%zd", cnt];
}

@end
